import { ICondition } from '../../interfaces';
import service from './service';

/**
 * 取数
 * @param url 请求地址
 * @param systemid 项目的systemid
 * @param refsystemid 项目的refsystemid
 * @param modelid 模块id
 * @param table_name 表名
 * @param condition 条件
 * @param cache 是否缓存
 * @param force_update_cache 是否即时刷新缓存
 * @return any[]
 * @example const res=await get_data(systemid, refsystemid, modelid, table_name, condition, cache, force_update_cache);
 */
export default async function get_data(systemid: string, refsystemid: string, modelid: string, table_name: string, condition: ICondition, cache: boolean, force_update_cache: boolean) {
	const params = {
		condition: condition || {
			paging: {
				index: 1,
				size: 12
			},
			param: {},
			sort: {}
		},
		emptydataflag: 0,
		modelid,
		refsystemid,
		systemid
	};
	const data = await service<{ docDataStore: { [table_name: string]: { dataArray: any[] } } }>('dataservice.findbusidata', params, cache, force_update_cache);
	const docDataStore = data.docDataStore;
	const table_data = docDataStore[table_name];
	const dataArray = table_data.dataArray;
	return dataArray;
}
